import msvcrt
from matplotlib import pyplot as plt
import numpy as np
import time

plt.rcParams['font.sans-serif']=['SimHei'] #Show Chinese label
plt.rcParams['axes.unicode_minus']=False   #These two lines need to be set manually
def scatter_plot():
    # 打开交互模式
    plt.ion()
    for index in range(50):
        # plt.cla()

        plt.title("动态散点图")
        plt.grid(True)

        point_count = 5
        x_index = np.random.random(point_count)
        y_index = np.random.random(point_count)
  
        color_list = np.random.random(point_count)
        scale_list = np.random.random(point_count) * 100

        plt.scatter(x_index, y_index, s=scale_list, c=color_list, marker="^")

        plt.pause(0.05)
        if msvcrt.kbhit() and msvcrt.getch() == b't':
            break

    plt.ioff()

    plt.show()
scatter_plot()